/*
 * @Author: lll 1280388921@qq.com
 * @Date: 2025-04-15 23:03:31
 * @LastEditors: lll 1280388921@qq.com
 * @LastEditTime: 2025-04-16 16:10:03
 * @FilePath: /lesson29/1.sharemem/processb.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"comm.hpp"

int main()
{
    //一旦有了共享内存，挂接到自己的地址空间中，你直接把它当成你的内存空间来用即可！
    //不需要调用系统调用
    //获取shmid
    int shmid=Getshm();
    // log(Debug,"get share memory done");

    //挂接
    char*shmaddr=(char*)shmat(shmid,nullptr,0);
    // log(Debug,"attach share memory done,shmaddr:0x%x",shmaddr);

    int fd=open(FIFO_FILE,O_WRONLY);
    if(fd<0)
    {
        log(Fatal,"error string: %s , error code: %d\n",strerror(errno),errno);
        exit(FIFO_OPEN_ERR);
    }
    //ipc code
    while(1)
    {
        cout<<"please enter:"<<endl;
        fgets(shmaddr,size,stdin);

        write(fd,"c",1);//通知对方
    }

    // sleep(5);

    //去关联
    shmdt(shmaddr);
    // log(Debug,"detach share memory done,shmaddr:0x%x",shmaddr);
    close(fd);
    return 0;
}